from subprocess import run, PIPE

from .service import Service


class GitBasedService(Service):
    def __init__(self, directory):
        super().__init__()
        self._directory = directory
        self._branch = '??'

    def update_branch(self):
        self._branch = run(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
                           stdout=PIPE,
                           cwd=self._directory).stdout.decode('utf-8').strip()
